package com.example.demo6_.controller;

import com.example.demo6_.entity.User;
import com.example.demo6_.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class login {
    @Resource
    private UserService userService;

    @RequestMapping("/loginOut")
    public String loginOut(HttpSession session){
        session.removeAttribute("user");
        return "aa";
    }

    @RequestMapping(value = "/doLogin")
    public String login(Model model, String name, String pwd, HttpSession session){
        User user = userService.findNameAndPassword(name,pwd);
        if (user!=null){
            session.setAttribute("user",user);
                return "main1";
        }else {
            model.addAttribute("message","账号或密码错误！");
            return "aa";
        }
    }
}
